#!/bin/sh


TZDHCP_MAIN_IP=`uci get tz_mgr.main.AP_IPADDR`
TZDHCP_MAIN_MASK=`uci get tz_mgr.main.AP_NETMASK`
DHCP_MAIN_MAC=`eth_mac r lan`


WIRED_WAN_MAC=`eth_mac r wan`

if [ "${TZDHCP_MAIN_IP}" = "" ]; then
		DHCP_MAIN_IP=192.168.2.1
else
		DHCP_MAIN_IP=${TZDHCP_MAIN_IP}
fi

if [ "${TZDHCP_MAIN_NETMASK}" = "" ]; then
		DHCP_MAIN_MASK=255.255.255.0
else
		DHCP_MAIN_MASK=${TZDHCP_MAIN_NETMASK}
fi


cat > /etc/config/network <<EOF

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fd05:bae0:fa6b::/48'

config interface 'lan'
	option ifname 'eth0.1 eth0.2'
	option force_link '1'
	option macaddr '${DHCP_MAIN_MAC}'
	option type 'bridge'
	option proto 'static'
	option ipaddr '${DHCP_MAIN_IP}'
	option netmask '${DHCP_MAIN_MASK}'
	option ip6assign '60'


config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '0 1 2 3 6t'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '4 6t'

EOF
